package com.ruoyi.wechat.service.impl;

import java.util.List;

import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.wechat.mapper.CDetailsMapper;
import com.ruoyi.wechat.service.ICDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.wechat.mapper.CAppointmentMapper;
import com.ruoyi.wechat.domain.CAppointment;
import com.ruoyi.wechat.service.ICAppointmentService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 营地预约管理Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-12-03
 */
@Service
public class CAppointmentServiceImpl implements ICAppointmentService 
{
    @Autowired
    private CAppointmentMapper cAppointmentMapper;
    @Autowired
    private ICDetailsService cDetailsService;

    /**
     * 查询营地预约管理
     * 
     * @param appointId 营地预约管理主键
     * @return 营地预约管理
     */
    @Override
    public CAppointment selectCAppointmentByAppointId(String appointId)
    {
        return cAppointmentMapper.selectCAppointmentByAppointId(appointId);
    }

    /**
     * 查询营地预约管理列表
     * 
     * @param cAppointment 营地预约管理
     * @return 营地预约管理
     */
    @Override
    public List<CAppointment> selectCAppointmentList(CAppointment cAppointment)
    {
        return cAppointmentMapper.selectCAppointmentList(cAppointment);
    }

    /**
     * 新增营地预约管理
     * 
     * @param cAppointment 营地预约管理
     * @return 结果
     */
    @Override
    @Transactional
    public int insertCAppointment(CAppointment cAppointment)
    {
        cAppointment.setAppointId(IdUtils.randomUUID());
        cAppointment.setAppointStatus(0L);
        //        将前端传的嵌套数据剥离储存
        for (int i = 0; i < cAppointment.getDetailsList().size(); i++) {
//            赋值预约ID
            cAppointment.getDetailsList().get(i).setAppointId(cAppointment.getAppointId());
//            赋值预约详情ID
            cAppointment.getDetailsList().get(i).setDetailsId(IdUtils.randomUUID());
            cDetailsService.insertCDetails(cAppointment.getDetailsList().get(i));
        }
        return cAppointmentMapper.insertCAppointment(cAppointment);
    }


    /**
     * 修改营地预约管理
     * 
     * @param cAppointment 营地预约管理
     * @return 结果
     */
    @Override
    public int updateCAppointment(CAppointment cAppointment)
    {
        return cAppointmentMapper.updateCAppointment(cAppointment);
    }

    /**
     * 批量删除营地预约管理
     * 
     * @param appointIds 需要删除的营地预约管理主键
     * @return 结果
     */
    @Override
    public int deleteCAppointmentByAppointIds(String[] appointIds)
    {
        return cAppointmentMapper.deleteCAppointmentByAppointIds(appointIds);
    }

    /**
     * 删除营地预约管理信息
     * 
     * @param appointId 营地预约管理主键
     * @return 结果
     */
    @Override
    public int deleteCAppointmentByAppointId(String appointId)
    {
        return cAppointmentMapper.deleteCAppointmentByAppointId(appointId);
    }
}
